package com.ruoyi.livedemo.mapper;

import com.ruoyi.livedemo.entity.User;
import java.util.List;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper {

    @Select("SELECT * FROM users WHERE id = #{id}")
    User findById(Long id);

    @Select("SELECT * FROM users WHERE username = #{username}")
    User findByUsername(String username);

    @Select("SELECT * FROM users ORDER BY id")
    List<User> findAll();

    @Insert("INSERT INTO users (username, password_hash, display_name, email, avatar_path, theme_preference) " +
            "VALUES (#{username}, #{passwordHash}, #{displayName}, #{email}, #{avatarPath}, #{themePreference})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(User user);

    @Update("UPDATE users SET display_name=#{displayName}, email=#{email}, avatar_path=#{avatarPath}, " +
            "theme_preference=#{themePreference}, updated_at=NOW() WHERE id=#{id}")
    int update(User user);
}


